<?php
/**
 * 巡展基金项目
 * @author jianhui
 *
 */
class XunProject extends MY_Controller{
    function XunProject(){
        parent::MY_Controller();
    }
    /**
     * 项目查看
     */
    function budgetCheck(){
        $activityId = trim($this->input->get('activityId'));
        $activityId || showError('请选择项目');
        //项目模型
        $this->load->model('xProjectModel');
        $projectData = $this->xProjectModel->getData(array('activityId'=>$activityId));
        $projectData || showError('项目数据不存在');
        $this->viewData['projectData'] = $projectData;
        $this->viewData['moneyDetail'] = $this->xProjectModel->getDetailMoney($activityId);
        //线上广宣
        $this->load->model('xPGxModel');
        $this->viewData['gxList'] = $this->xPGxModel->getNewList(array('activityId'=>$activityId));
        //线下活动
        $this->load->model('xPOfflineModel');
        $this->viewData['offlineList'] = $this->xPOfflineModel->getNewList(array('activityId'=>$activityId));
        //查看标记
        $this->viewData['action'] = 'check';
        $this->load->view('XunProject/budgetCheck', $this->viewData);
    }
    /**
     * 项目结算查看
     */
    function settleCheck(){
        $activityId = trim($this->input->get('activityId'));
        $activityId || showError('请选择项目');
        //项目模型
        $this->load->model('xProjectModel');
        $projectData = $this->xProjectModel->getData(array('activityId'=>$activityId));
        $projectData || showError('项目数据不存在');
        $this->viewData['projectData'] = $projectData;
        $this->viewData['moneyDetail'] = $this->xProjectModel->getDetailMoney($activityId);
        //线上广宣
        $this->load->model('xPGxModel');
        $this->viewData['gxList'] = $this->xPGxModel->getNewList(array('activityId'=>$activityId));
        //线下活动
        $this->load->model('xPOfflineModel');
        $this->viewData['offlineList'] = $this->xPOfflineModel->getNewList(array('activityId'=>$activityId));
        //查看标记
        $this->viewData['action'] = 'check';
        $this->load->view('XunProject/settleCheck', $this->viewData);
    }
    /**
     * 项目结算审核
     */
    function settleAudit(){
        $this->load->model('xProjectModel');
        $this->load->model('xPGxModel');
        $this->load->model('xPOfflineModel');
        if ($_POST){
            $activityId = trim($this->input->get('activityId'));
            $activityId || showError('请选择项目');
            $gxData = $this->input->post('gx');
            $offlineData = $this->input->post('offline');
            if (!$gxData && !$offlineData){
                showError('请还未选择审核项');
            }
            if ($gxData){
                foreach ($gxData as $k => $v){
                    $this->xPGxModel->settleAudit($k, (int)$v['settleAuditRs'], $this->user);
                }
            }
            if ($offlineData){
                foreach ($offlineData as $k => $v){
                    $this->xPOfflineModel->settleAudit($k, (int)$v['settleAuditRs'], $this->user);
                }
            }
            $this->xProjectModel->edit(array('activityId'=>$activityId), array('settleAuditDetail'=>1,'settleAuditRole'=>$this->user['userRole']));
            $this->xProjectModel->settleUpdateStatus($activityId);
            //更新项目金额
            $this->xProjectModel->updateMoney($activityId);
            showSuccess('审核成功');
        }else{
            $activityId = trim($this->input->get('activityId'));
            $activityId || showError('请选择项目');
            //项目模型
            $projectData = $this->xProjectModel->getData(array('activityId'=>$activityId));
            $projectData || showError('项目数据不存在');
            $this->viewData['projectData'] = $projectData;
            $this->viewData['moneyDetail'] = $this->xProjectModel->getDetailMoney($activityId);
            //线上广宣
            $this->viewData['gxList'] = $this->xPGxModel->getNewList(array('activityId'=>$activityId, 'settleAuditRs >' => -1));
            //线下活动
            $this->viewData['offlineList'] = $this->xPOfflineModel->getNewList(array('activityId'=>$activityId, 'settleAuditRs >' => -1));
            //查看标记
            $this->viewData['action'] = 'audit';
            $this->load->view('XunProject/settleAudit', $this->viewData);
        }
    }
}